package com.ktjiaoyu.mapper;

import com.ktjiaoyu.pojo.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SysUserMapper {
    /**
     * 新怎
     *
     * @param sysUser
     * @return
     */
    @Insert("INSERT INTO `springboot`.`sys_user`(`usr_name`, `usr_password`, `usr_role_id`, `usr_flag`)" +
            "VALUES (#{usrName}, #{usrPassword}, #{usrRoleId}, #{usrFlag})")
    public int insert(SysUser sysUser);

    @Select("SELECT * FROM `springboot`.`sys_user` ")
    @Results(
            {
                @Result(column = "usr_id",property = "usrId",id = true),
                @Result(column = "usr_name",property = "usrName"),
                @Result(column = "usr_password",property = "usrPassword"),
                @Result(column = "usr_role_id",property = "usrRoleId"),
                @Result(column = "usr_flag",property = "usrFlag")
            }
    )
    public List<SysUser> selectList();

    @Update("<script>"+
            "UPDATE sys_user" +
            "<set>" +
            "<if test='usrName!=null and usrName!='>" +
                "usr_name = #{usrName}," +
            "</if>" +
            "<if test=\"usrPassword!=null and usrPassword!=''\">" +
                "usr_password = #{usrPassword}," +
            "</if>" +
            "<if test=\"usrRoleId!=null\">" +
                "usr_role_id = #{usrRoleId}," +
            "</if>" +
            "<if test=\"usrFlag!=null\">" +
                "usr_flag = #{usrFlag}," +
            "</if>" +
            "</set>" +
            "WHERE usr_id = #{usrId}"+
    "</script>")
    public int update(SysUser sysUser);
}
